# Kernel Development The Debian system includes the kernel header files required for kernel module development and provides the toolchain needed to compile kernel modules. Users can directly develop and build new kernel modules on the device. # Environment Preparation ```plaintext sudo apt update sudo apt install -y make ``` # Write the Source Code ## helloworld.c File The contents of the helloworld.c file are as follows: ```cpp #include #include #include MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("A simple Hello World kernel module"); MODULE_VERSION("0.1"); static int __init helloworld_init(void) { printk(KERN_INFO "Hello World!\n"); return 0; } static void __exit helloworld_exit(void) { printk(KERN_INFO "Goodbye!\n"); } module_init(helloworld_init); module_exit(helloworld_exit); ``` ## Makefile File The contents of the Makefile are as follows: ```javascript obj-m := helloworld.o KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) all: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: $(MAKE) -C $(KERNELDIR) M=$(PWD) clean install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install help: $(MAKE) -C $(KERNELDIR) M=$(PWD) help .PHONY: all clean install help ``` # Build Build command: ```plaintext LD_LIBRARY_PATH=/opt/qcom/lib:$LD_LIBRARY_PATH PATH=/opt/quectel/bin:$PATH make LLVM=1 ``` # Run and Test Load the module: ```plaintext insmod helloworld.ko ``` Check the result: ```plaintext lsmod | grep helloworld ``` Unload the module: ```plaintext rmmod helloworld ``` Check the kernel log: ```plaintext dmesg | grep "Hello World" ```